package 动态规划.最小花费爬楼梯;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/2/7 21:16
 * @description:
 * @version:
 */
public class Solution {
    public static void main(String[] args) {
        int[] array = {1,100,1,1,1,100,1,1,100,1};
        System.out.println(minCostClimbingStairs(array));
    }

    //动态规划
    //minCost[i] = min(minCost[i-1] + cost[i], minCost[i-2] + cost[i-1])
    //第0阶台阶 minCost[0] = min(cost[-1], cost[0]) = min(0, cost[0]) = 0
    //第1阶台阶 minCost[1] = min(cost[0], cost[1])
    public static int minCostClimbingStairs(int[] cost) {
        int size = cost.length;
        int[] minCost = new int[size];
        minCost[0] = 0;
        minCost[1] = Math.min(cost[0], cost[1]);
        for (int i = 2; i < size; i++) {
            minCost[i] = Math.min(minCost[i - 1] + cost[i], minCost[i - 2] + cost[i - 1]);
        }
        return minCost[size - 1];
    }
}
